package module.scene.model.dataObj
{
	import com.darwin.darwinIsometric.core.IsoPosition;
	import com.darwin.darwinIsometric.core.Point3D;
	
	import flash.geom.Point;
	
	import module.building.model.dataObj.BuildingObj;
	import module.scene.consts.SceneConst;
	import module.scene.utils.SceneUtil;
	

	/**
	 *	所有地图物件数据结构基类，地图上的物件强类型必须继承此类
	 * @author Roland
	 * 
	 */
	public class IsoDataObj
	{
		public function IsoDataObj()
		{
		}
		
		private var _serverId:String;

		/**
		 *	物件id 
		 */
		public function get serverId():String
		{
			return _serverId;
		}

		/**
		 * @private
		 */
		public function set serverId(value:String):void
		{
			_serverId = value;
		}

		/**
		 *	物件所属用户id 
		 */
		public var userId:String;
		
		/**
		 * 动态物件实体id,世界唯一标示 
		 */
		public var eId:String;
		
		/**
		 *	 物件占格
		 */
		public var size:int;
		
		/**
		 *	物件所处全局绝对坐标 x(基于格子)
		 */
		public var absX:int;
		/**
		 *	物件所处全局绝对坐标 y(基于格子)
		 */
		public var absY:int;
		/**
		 *	物件所处全局绝对坐标 z(基于格子)
		 */
		public var absZ:int;
		
		/**
		 *	物件方向 
		 */
		public var direction:int;
		
		/**
		 *	物件是否可通行 (1：可通行，0：不可通行)
		 */
		public var walkable:int = 1;
		
		/**
		 *	是否自动拼接 
		 */
		public var isCombo:Boolean = false;
		/**
		 *	拼接码
		 */
		public var comboRim:String = "0000";
		
		/**
		 *	组合部件码[表示为组合部件的第几个部分(1~4)，默认为0表示非组合部件]
		 */
		public var partId:int = 0;
		
		/**
		 *	是否连续放置/拆除 
		 */
		public var placedConsecutively:Boolean = false;
		/**
		 *	物件在场景中的坐标(基于像素)
		 * @return 
		 * 
		 */
		public function get postion3D():Point3D
		{
			var pos:IsoPosition = SceneUtil.absPosToRelPos(absX,absZ);
			return new Point3D(pos.x*SceneConst.GRID_SIZE,0,pos.z*SceneConst.GRID_SIZE);
		}
		
		/**
		 *	物件iso类型 
		 */
		public var isoType:String;
		
		/**
		 *	填充物件动态数据 
		 * @param data
		 * 
		 */
		public function parseDynamicData(data:Object):void
		{
			
		}
		
		public function clone():IsoDataObj
		{
			var $obj:IsoDataObj = new IsoDataObj();
			$obj.serverId = this.serverId;
			$obj.absX = this.absX;
			$obj.absZ = this.absZ;
			$obj.direction = this.direction;
			$obj.size = this.size;
			$obj.walkable = this.walkable;
			$obj.isoType = this.isoType;
			$obj.comboRim = this.comboRim;
			$obj.userId = this.userId;
			$obj.eId = this.eId;
			$obj.isCombo = this.isCombo;
			$obj.placedConsecutively = this.placedConsecutively;
			return $obj;
		}
		
		/**
		 *	填充物件配置信息 
		 * @param data
		 * @return 
		 * 
		 */
		public static function parseData(data:Object):IsoDataObj
		{
			var $obj:IsoDataObj = new IsoDataObj();
			if(data.hasOwnProperty("serverId")) $obj.serverId = data.serverId;
			else if(data.hasOwnProperty("id")) $obj.serverId = data.id;
			if(data.hasOwnProperty("x")) $obj.absX = data.x;
			if(data.hasOwnProperty("z")) $obj.absZ = data.z;
			if(data.hasOwnProperty("direction")) $obj.direction = data.direction;
			if(data.hasOwnProperty("size")) $obj.size = data.size;
			if(data.hasOwnProperty("walkable")) $obj.walkable = data.walkable;
			if(data.hasOwnProperty("isoType")) $obj.isoType = data.isoType;
			if(data.hasOwnProperty("comboRim"))$obj.comboRim = data.comboRim;
			if(data.hasOwnProperty("isCombo"))$obj.isCombo = Boolean(int(data.isCombo));
			if(data.hasOwnProperty("placedConsecutively"))$obj.placedConsecutively = Boolean(int(data.placedConsecutively));
			return $obj;
		}
	}
}